#include <iostream>
#include <glib.h>
#include <gio/gio.h>

void launched(
    GAppLaunchContext *self,
    GAppInfo *info,
    GVariant *platform_data,
    gpointer user_data)
{
    std::cout << "======" << std::endl;
}

void launch_failed(
    GAppLaunchContext *self,
    gchar *startup_notify_id,
    gpointer user_data)
{
    std::cout << "==ssddd====" << std::endl;
}

void changed(
    GAppInfoMonitor *self,
    gpointer user_data)
{
    std::cout << "==ssdasdasdadsdd====" << std::endl;
}
int main(int argc, char **argv)
{
    GMainLoop *ws = g_main_loop_new(NULL, FALSE);
    GAppLaunchContext *a = g_app_launch_context_new();
    std::cout << "a:" << a << std::endl;
    g_signal_connect(a, "launched", G_CALLBACK(launched), NULL);
    g_signal_connect(a, "launch-failed", G_CALLBACK(launch_failed), NULL);

    GAppInfoMonitor *app_monitor = g_app_info_monitor_get();
    g_signal_connect(app_monitor, "changed", G_CALLBACK(changed), NULL);

    auto list = g_app_info_get_all();
    std::cout << "list:" << list << std::endl;

    GAppInfo *app = (GAppInfo *)list->data;
    std::cout << "app:" << g_app_info_get_name(app) << std::endl;
    g_app_info_launch(app, NULL, a, NULL);

    g_main_loop_run(ws);
    g_object_unref(a);
    std::cout << "sss" << std::endl;
    g_object_unref(ws);

    return 0;
}